package Song.Han.Demo01;
/*
        1.虚拟机启动，先初始化main方法所在类
        2.若父类未被初始化。先初始化父类
*/
public class Demo05 {
    static {
        System.out.println("Main类被加载");
    }

    public static void main(String[] args) throws ClassNotFoundException {
    //主动引用
        //1.new
        //Son son = new Son();

        //2.反射
        //Class.forName("Song.Han.Demo01.Son");

    //不会产生类的引用的方法
        //子类调用静态方法或变量
        //System.out.println(Son.b);//子类未被加载

        //通过数组定义类引用
        //Son[] array = new Son[5];//只有main类被加载

        //引用常量
        System.out.println(Son.M);//只有main类被加载
    }
}

class Father {

    static int b = 2;
    static {
        System.out.println("父类被加载");
    }
}

class Son extends Father {

    static {
        System.out.println("子类被加载");
        m = 300;
    }

    static int m = 100;
    static final int M = 1;

}